#include "bn_core.h"
#include "bn_common.h"
#include "bn_bg_palettes.h"
#include "bn_keypad.h"
#include "bn_sprite_font.h"

#include "dt_8x8_variable.h"

#include "scenario_test.h"
#include "vn_text_output.h"

namespace
{
    constexpr int kTestScenarioLength{10};
}

int main()
{
    bn::core::init();

    const bn::sprite_font font{bn::sprite_items::deadline_tracker_8x8, utf8_chars_map.reference(), character_widths};

    bn::sprite_text_generator txt{font};
    bn::sprite_text_generator* text_ptr{&txt};

    bn::bg_palettes::set_transparent_color(bn::color(15,15,15));

    const bn::string_view test[] =
    {
        "It's the same code from last year except I've returned to working on it lol",
        "Things to figure out for now:",
        "1) make text output make sense, learn how gba windows work and how to incorporate stuff like variables, text colors, output speed etc",
        "2) work on the isometric exploration part of the game, namely collisions, camera and whatnot",
        "3) build a game state machine and make use of more programming patterns in general because i am a professional",
        "4) see if i can replicate some of the midi music using up to 10 channels",
        "5) have fun in the process",
        "Yeah for some reason sometimes I cannot print out multiple lines on loop, perhaps a complete rehaul of text output code will help",
        "why isn't this working though I'm pretty sure it worked before",
        "anyways there's still a lot of work to be done on the game"
    };

    int script_ptr{0};
    int line_ptr{0};
    int symbol_ptr{0};
    bool apply_effect{true};
    const bn::string_view current_line{test[script_ptr]};
    text _text(current_line, text_ptr);

    scenario_test scenarioTest{};

    while (1)
    {
        if (apply_effect) apply_effect = _text.output_Typewriter(test[script_ptr], symbol_ptr, line_ptr);
        if (bn::keypad::a_pressed())
        {
            if (apply_effect)
            {
                apply_effect = false;
                _text.output_NoEffect(test[script_ptr]);
            }
            else
            {
                script_ptr = script_ptr + 1 >= kTestScenarioLength ? 0 : script_ptr + 1;
                line_ptr = 0;
                symbol_ptr = 0;
                _text.redraw(test[script_ptr]);
                apply_effect = true;
            }
        }

        scenarioTest.scenarioUpdate();

        bn::core::update();
    }
}
